<?php
    //require section
    require_once dirname(dirname(__FILE__)) . '/shared/config/config.php';
    require_once DOCUMENT_ROOT . DIR_INCLUDE . '/check_user_login.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_config.php';
    $title = 'Configuration';

    $txt_ep = filter_input(INPUT_POST, 'txt_ep');
    $txt_skrill_email = filter_input(INPUT_POST, 'txt_skrill_email');
    $btn_save = filter_input(INPUT_POST, 'btn_save');

    if (!empty($btn_save)) {
        if(api_config::set_easypaisa_detail($txt_ep)){
            $success_info = "Successful save easypaisa detail!";
        } else {
            $error_show = "Failed to save easypaisa detail!";
        }

        if(api_config::set_skrill_email($txt_skrill_email)){
            $success_info .= " || Successful save skrill email!";
        } else {
            $error_show .= "Failed to save skrill email";
        }
    }

    $ep_description = api_config::get_easypaisa_detail();
    $skrill_email = api_config::get_skrill_email();
?>

<!DOCTYPE html>
<html>
<head>
    <?php
        require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'head.php';
    ?>
    <script src="<?php echo LINK_ROOT . DIR_SHARED_PLUGIN . 'ckeditor/ckeditor.js' ?>"></script>;
</head>
<body>
<div class="ui page grid">
    <div class="column ts-wrapper">
        <?php
            require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'header.php';
        ?>
        <div class="ts-inner-wrapper">
            <h1>Configuration</h1>
            <?php if (!empty($error_show)) { ?>
                <div class="ui error message">
                    <i class="close icon"></i>

                    <div class="header">
                        Please correct these wrongs.
                    </div>
                    <ul class="list">
                        <?php echo $error_show; ?>
                    </ul>
                </div>
            <?php
            } else if (!empty($success_info)) {
                ?>
                <div class="ui success message">
                    <i class="close icon"></i>

                    <div class="header">
                        <?php echo $success_info; ?>
                    </div>
                </div>
            <?php
            }
            ?>
            <div class="hide" id="add-edit-popup">
                <form name="form_data" id="form_data" method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" enctype="multipart/form-data">
                    <div class="ui form segment form-background">

                        <div class="field">
                            <label for="Title">EasyPaisa Option Description <span class="required">*</span></label>
                            <!--                            <input name="txt_ep_description" value="-->
                            <?php //echo $ep_description; ?><!--" placeholder="EasyPaisa Checkout Description" type="text">-->
                            <textarea class="ckeditor" name="txt_ep" placeholder="EasyPaisa Checkout Description" required><?php echo $ep_description; ?></textarea>
                        </div>

                        <div class="field">
                            <label for="Name">Skrill Merchant Email <span class="required">*</span></label>
                            <input type="text" name="txt_skrill_email" value="<?php echo $skrill_email; ?>" placeholder="Merchant Email" required/>
                        </div>

                        <input type="submit" value="Save" name="btn_save" class="ui orange button">
                    </div>
                </form>
            </div>

            <script type="text/javascript">
                show_popup();
            </script>
        </div>
        <?php
            require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'footer.php';
        ?>
    </div>
</div>
</body>
</html>